package com.hjy.controller;

import com.hjy.service.IEfsService;
import com.hjy.websocket.domain.StudentTest;
import com.hjy.websocket.domain.WbsocketResponseBody;
import com.hjy.websocket.domain.WebSocketRequest;
import com.hjy.websocket.websocketservice.ICWebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/test")
@Api(tags = "制器")
public class RequestTestController {

    private final ICWebSocketServer icWebSocketServer;
    public RequestTestController( ICWebSocketServer icWebSocketServer) {
        this.icWebSocketServer = icWebSocketServer;
    }
    @ApiOperation("测试不同类型请求")
    @GetMapping("/testType")
    public WbsocketResponseBody openCabinet() {
        List<String> strings = new ArrayList<>();
        strings.add("test");
        StudentTest studentTest = new StudentTest();
        studentTest.setName("小明");
        studentTest.setNames(strings);
        List<StudentTest> studentTests = new ArrayList<>();
        studentTests.add(studentTest);

        HashMap<String, StudentTest> studentTestMap = new HashMap<>();
        studentTestMap.put("test", studentTest);
        WebSocketRequest webSocketRequest = WebSocketRequest.create("testType",new Object[]{ studentTest,  studentTests,  strings, studentTestMap}, "192.168.1.168");
        WbsocketResponseBody wbsocketResponseBody = icWebSocketServer.sendMessageSynchronous(webSocketRequest);
        return wbsocketResponseBody;

    }

    @ApiOperation("测试开柜请求(异步)")
    @GetMapping("/openCabinetA")
    public void openCabinetA(@RequestParam("param") String param) {

        WebSocketRequest webSocketRequest = WebSocketRequest.create("openCabinet",new Object[]{param}, "192.168.1.168");
        icWebSocketServer.sendMessageAsynchronous(webSocketRequest);
    }



    @ApiOperation("测试开柜请求(同步)")
    @GetMapping("/openCabinetS")
    public WbsocketResponseBody openCabinetS(@RequestParam("param") String param) {

        WebSocketRequest webSocketRequest = WebSocketRequest.create("openCabinet",new Object[]{param}, "192.168.1.168");
        WbsocketResponseBody wbsocketResponseBody = icWebSocketServer.sendMessageSynchronous(webSocketRequest);
        return wbsocketResponseBody;
    }



    @ApiOperation("测试同步请求")
    @GetMapping("/synchronousRequest")
    public WbsocketResponseBody synchronousRequest(@RequestParam("param") String param) {

        WebSocketRequest webSocketRequest = WebSocketRequest.create("test",new Object[]{param}, "192.168.1.168");
        WbsocketResponseBody wbsocketResponseBody = icWebSocketServer.sendMessageSynchronous(webSocketRequest);
        return wbsocketResponseBody;
    }


    @ApiOperation("测试异步请求")
    @GetMapping("/asynchronousRequest")
    public void asynchronousRequest(@RequestParam("param") String param) {

        WebSocketRequest webSocketRequest = WebSocketRequest.create("test",  new Object[]{param}, "192.168.1.168");
        icWebSocketServer.sendMessageAsynchronous(webSocketRequest);
    }
}
